package action;

import conexao.FabricaDeConexao;
import dao.JDBCOpcoesMenuDao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PesquisandoDB extends HttpServlet {

   private static final long serialVersionUID = 1L;
    JDBCOpcoesMenuDao JDBCOpcoes;
    FabricaDeConexao conecta = new FabricaDeConexao();
    Connection conexao;
    Statement st;
    ResultSet rs;
    String query;

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException {
    }

    /**
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        String pesquisa = request.getParameter("txtNovaBusca");

        boolean resp;

        JDBCOpcoesMenuDao dao = new JDBCOpcoesMenuDao(conecta, conexao, null, null, query);
        resp = dao.ValidaPesquisa(pesquisa);

        if (resp) {
            response.sendRedirect("http://localhost:8080/MarmitexOnlineTaiti/faces/lista_menu.xhtml");
        } else {
            response.sendRedirect("http://localhost:8080/MarmitexOnlineTaiti/faces/Respota_Pesquisa.xhtml");
        }
    }
}
